package com.yunxi.controller.otd;

import com.yunxi.core.web.ApiResult;
import com.yunxi.core.web.ResponseUtil;
import com.yunxi.hubToBiz.service.OtdSendPlanDubboService;
import com.yunxi.otd.pojo.OtdInterfaceConfigQueryVO;
import com.yunxi.otd.pojo.OtdInterfaceConfigVO;
import com.yunxi.otd.pojo.OtdOrderSoEditVO;
import com.yunxi.otd.service.OtdInterfaceConfigDubboService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import java.util.List;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * SO、CIR接口时间设置 前端控制器
 * </p>
 *
 * @author XUQI
 * @since 2019-07-10
 */
@RestController
@RequestMapping("/admin/otd/if/config")
@Api(tags = "OTD:INTERFACECONFIG", description = "SO、CIR接口时间设置接口")
public class OtdInterfaceConfigController {

    private static final Logger logger = LoggerFactory.getLogger(OtdInterfaceConfigController.class);

    @Autowired
    OtdInterfaceConfigDubboService otdInterfaceConfigDubboService;


    @Autowired
    OtdSendPlanDubboService otdSendPlanDubboService;

    @GetMapping("/page")
    @ApiOperation(value = "查询分页")
    public ApiResult page(OtdInterfaceConfigQueryVO queryVO, Integer pageNum, Integer pageSize) {
        return ResponseUtil.ok(otdInterfaceConfigDubboService.findPageByVO(queryVO, pageNum, pageSize));
    }

    @GetMapping("/list")
    @ApiOperation(value = "查询列表")
    public ApiResult list(OtdInterfaceConfigVO otdInterfaceConfigVO) {
        return ResponseUtil.ok(otdInterfaceConfigDubboService.listByVo(otdInterfaceConfigVO));
    }

    @GetMapping("/load")
    @ApiOperation(value = "读取单个")
    public ApiResult load(String id) {
        return ResponseUtil.ok(otdInterfaceConfigDubboService.getById(id));
    }

    @PostMapping("/save")
    @ApiOperation(value = "保存信息")
    public ApiResult save(@RequestBody OtdInterfaceConfigVO configVO) {
        return otdInterfaceConfigDubboService.saveOrUpdate(configVO);
    }

    @PostMapping("/remove")
    @ApiOperation(value = "删除")
    public ApiResult remove(@RequestBody List<String> ids) {
        otdInterfaceConfigDubboService.removeByIds(ids);
        return ResponseUtil.ok();
    }

    @PostMapping("/send")
    @ApiOperation(value = "接口触发")
    public ApiResult send() {
        return otdSendPlanDubboService.sendPlan();
    }

    @GetMapping("/send/day")
    public ApiResult getSendDays(String yearMonth, String type) {
        return otdInterfaceConfigDubboService.getSendDays(yearMonth, type);
    }
//    @PostMapping("/del")
//    @ApiOperation(value = "删除")
//    public ApiResult del(@RequestBody List<String> ids) {
//        otdInterfaceConfigDubboService.removeByIds(ids);
//        return ResponseUtil.ok("success");
//    }
}
